# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName : p22.py
# @Time     : 2024/5/12 18:30
# @Author   : Robot-Zsj
"""
description:

启动多任务排序

https://fcqian.blog.csdn.net/article/details/135268369

i:
A->B C->B

o:
B A C

"""
relations = list(map(lambda s: s.split("->"), input().split()))


def getResult():
    inDegree = {}
    next = {}

    for a, b in relations:
        inDegree[b] = inDegree.get(b, 0)
        inDegree[a] = inDegree.get(a, 0) + 1

        next[b] = next.get(b, [])
        next[b].append(a)

        next[a] = next.get(a, [])

    queue = []
    for task in inDegree:
        if inDegree[task] == 0:
            queue.append(task)

    ans = []

    while len(queue) > 0:
        queue.sort()

        newQueue = []
        for fa in queue:
            ans.append(fa)

            for ch in next[fa]:
                inDegree[ch] -= 1

                if inDegree[ch] == 0:
                    newQueue.append(ch)
        queue = newQueue
    return " ".join(ans)


print(getResult())
